package org.tinygroup.trans.xstream.springtrans;

import org.springframework.messaging.Message;
import org.tinygroup.trans.xstream.util.XStreamConvertUtil;

public class XStreamTransformService {
	private static final String XSTREAM_SCENE = "BIZ_SCENE";

	/**
	 * xml转对象，采用xstream的方式
	 * 
	 * @param inMessage
	 * @return
	 */
	public Object transfor2Object(Message<?> inMessage) {
		String scene = (String) inMessage.getHeaders().get(XSTREAM_SCENE);
		return (Object) XStreamConvertUtil.convert(inMessage.getPayload(),
				scene);
	}

	/**
	 * 对象转xml，采用xstream的方式
	 * 
	 * @param inMessage
	 * @return
	 */
	public String transfor2Xml(Message<?> inMessage) {
		String scene = (String) inMessage.getHeaders().get(XSTREAM_SCENE);
		return (String) XStreamConvertUtil.convert(inMessage.getPayload(),
				scene);
	}

}
